package com.zttek.photosShareProject.modules.web.share;

import com.zttek.photosShareProject.common.base.MyBaseController;
import com.zttek.photosShareProject.common.json.ShareVO;
import com.zttek.photosShareProject.common.json.UserVO;
import com.zttek.photosShareProject.common.solr.ShareDoc;
import com.zttek.photosShareProject.common.solr.UserDoc;
import com.zttek.photosShareProject.modules.service.share.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Y
 * Date: 2017-09-07
 * Time: 17:22
 */
@RequestMapping("/search")
@Controller
public class SearchController extends MyBaseController {

    @Autowired
    private ISearchService searchService;

    @RequestMapping(value = "/share", method = RequestMethod.POST)
    @ResponseBody
    public Object searchShare(@RequestBody ShareVO.SearchForm form) throws Exception {
        List<ShareDoc> shareDocs = searchService.searchForShare(form.getPageNum(), form.getPageSize(), form.getQ());
        List<ShareVO> shareVOs = searchService.shareDoc2VO(shareDocs, form.getUserId());
        return renderSuccess(shareVOs);
    }

    @RequestMapping(value = "/user", method = RequestMethod.POST)
    @ResponseBody
    public Object searchUser(@RequestBody UserVO.SearchForm form) throws Exception {
        List<UserDoc> userDocs = searchService.searchForUser(form.getPageNum(), form.getPageSize(), form.getQ());
        List<UserVO> userVOs = searchService.userDoc2VO(userDocs, form.getUserId());
        return renderSuccess(userVOs);
    }
}
